package com.witer.colorswitch;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.witer.colorswitch.view.ColorSwitchView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView iv_color=findViewById(R.id.iv_color);
        ColorSwitchView color_picker =  findViewById(R.id.color_picker);
        color_picker.setOnColorChangeListener(new ColorSwitchView.OnColorViewChangeListener() {
            @Override
            public void onColorChange(int color) {
                iv_color.setBackgroundColor(color);
            }

            @Override
            public void onColorComplete(int color) {
                iv_color.setBackgroundColor(color);
//                //选中的颜色
//                Intent intent = new Intent();
//                intent.putExtra("colors", color);
//                setResult(Activity.RESULT_OK, intent);
//                finish();
            }
        });
    }
    /**
     * 获取亮度改变后的颜色
     *
     * @param color 颜色
     * @param br    亮度 0.0-1.0
     * @return
     */
    private int getColorBr(int color, float br) {
        float[] hsv = new float[3];
        Color.colorToHSV(color, hsv);
        hsv[2] = br;
        return Color.HSVToColor(hsv);
    }
}
